#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int s[1010][1010];
void fun()
{
	int k = 1;
	for (int i = 'a'; i <= 'z'; i++) {
		for (int j = 'a'; j <= 'z'; j++) {
			if (i != j) {
				s[i][j] = k++;
			}
		}
	}
}
int main()
{
	int t = 0;
	cin >> t;
	fun();
	while (t--) {
		char c, d;
		cin >> c >> d;
		cout << s[(int)c][(int)d] << endl;
	}
	return 0;
}